package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.model.order.OrderInfo;
import com.atguigu.gmall.order.client.OrderFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lfh
 * @version 1.0
 * @date 2021/4/30 16:39
 */
@Controller
public class PaymentController {

    @Autowired
    private OrderFeignClient orderFeignClient;

    // http://payment.gmall.com/pay.html?orderId=192
    @GetMapping("pay.html")
    public String pay(HttpServletRequest request){   // String因为要返回的是一个视图要渲染页面
        // 获取orderId
        String orderId = request.getParameter("orderId");
        // ${orderInfo} 存储orderInfo
        OrderInfo orderInfo = orderFeignClient.getOrderInfo(Long.parseLong(orderId));
        // 保存对象！
        request.setAttribute("orderInfo",orderInfo);
        return "payment/pay";
    }

    /**
     * 支付成功页
     * @return
     */
    @GetMapping("pay/success.html")
    public String paySuccess() {
        return "payment/success";
    }

}
